import 'package:flutter/material.dart';
import 'package:flutter_widget/custom/custom_appbar.dart';
// ignore: import_of_legacy_library_into_null_safe
import 'package:provider/provider.dart';
import 'package:flutter_widget/provider/color_them_provider.dart';
import 'package:flutter_widget/utils/theme.dart';

// ignore: must_be_immutable
class ChangeTheme extends StatefulWidget {
  String name;
  ChangeTheme({Key? key, required this.name}) : super(key: key);

  @override
  _ChangeThemeState createState() => _ChangeThemeState();
}

// ignore: camel_case_types
class _ChangeThemeState extends State<ChangeTheme> {
  final List colorList = ColorListUtils.colorList;

  @override
  Widget build(BuildContext context) {
    final MaterialColor color = Provider.of<ColorThemeProvider>(context).color;
    return Scaffold(
      appBar: CustomAppbar(widget.name, Theme.of(context).primaryColor),
      body: Center(
        child: Column(
          children: [
            ExpansionTile(
              title: Text(widget.name),
              leading: const Icon(Icons.color_lens),
              textColor: color,
              iconColor: color,
              children: [
                Padding(
                  padding: const EdgeInsets.all(10.0),
                  child: Wrap(
                    spacing: 10,
                    runSpacing: 10,
                    children: colorList.map((e) {
                      final isCheck = e == color;
                      return Material(
                        color: colorList[colorList.indexOf(e)],
                        child: InkWell(
                          onTap: () {
                            Provider.of<ColorThemeProvider>(context,
                                    listen: false)
                                .changeColor(colorList.indexOf(e));
                          },
                          child: SizedBox(
                            height: 50,
                            width: 50,
                            child: isCheck
                                ? const Icon(
                                    Icons.check,
                                    color: Colors.white,
                                  )
                                : null,
                          ),
                        ),
                      );
                    }).toList(),
                  ),
                )
              ],
            ),
          ],
        ),
      ),
    );
  }
}
